package com.ysd.lis.util;


import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.lis.entity.SysInterface;
import com.ysd.lis.entity.SysInterfaceDict;
import com.ysd.lis.entity.SysInterfaceMethod;
import com.ysd.lis.mapper.SysInterfaceDictMapper;
import com.ysd.lis.mapper.sys.SysInterfaceMapper;
import com.ysd.lis.mapper.sys.SysInterfaceMethodMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class InterfaceUtil {

    @Autowired
    SysInterfaceMethodMapper sysInterfaceMethodMapper;
    @Autowired
    SysInterfaceMapper sysInterfaceMapper;
    @Autowired
    SysInterfaceDictMapper sysInterfaceDictMapper;

    //根据methodCode获取所有方法
    public List<SysInterfaceDict> getAllSysInterfaceDict(String methodCode) {
        MPJLambdaWrapper<SysInterfaceDict> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(SysInterfaceDict.class);
        queryWrapper.selectAs(SysInterface::getInterfaceUrl,SysInterfaceDict::getWebUrl);
        queryWrapper.innerJoin(SysInterfaceMethod.class, "method", p -> p.eq(SysInterfaceMethod::getInterfaceDictId, SysInterfaceDict::getId).eq(SysInterfaceMethod::getDelFlag, 0));
        queryWrapper.innerJoin(SysInterface.class,"dict", p -> p.eq(SysInterfaceMethod::getInterfaceId, SysInterface::getId).eq(SysInterface::getDelFlag, 0));
        queryWrapper.eq(SysInterface::getIsEnable,1).eq(SysInterface::getDelFlag,0);
        queryWrapper.eq(SysInterfaceMethod::getIsEnable,1).eq(SysInterfaceMethod::getDelFlag,0);
        queryWrapper.eq(SysInterfaceDict::getDelFlag,0);
        queryWrapper.eq(SysInterfaceDict::getCode,methodCode);
        return sysInterfaceDictMapper.selectList(queryWrapper);
    }
}
